package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysUserRole;
import io.mybatis.example.springboot.service.SysUserRoleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_user_role - 用户和角色关联表
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysUserRoles")
public class SysUserRoleController {

  @Autowired
  private SysUserRoleService sysUserRoleService;

  @PostMapping
  public DataResponse<SysUserRoleDO> save(@RequestBody SysUserRoleDO sysUserRole) {
    return DataResponse.ok(sysUserRoleService.save( sysUserRole));
  }

  @GetMapping
  public RowsResponse<SysUserRoleDO> findList(@RequestBody SysUserRoleDO sysUserRole) {
    return RowsResponse.ok(sysUserRoleService.findList( sysUserRole));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysUserRoleDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysUserRoleService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysUserRoleDO> update(@PathVariable("id") Long id, @RequestBody SysUserRoleDO sysUserRole) {
    sysUserRole.setId(id);
    return DataResponse.ok(sysUserRoleService.update( sysUserRole));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysUserRoleService.deleteById(id) == 1);
  }

}
